home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 7 / develop 7 code / QuickTime / SimpleInMovies / SimpleInLOOP.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-15  |  6.2 KB  |  200 lines  |  [TEXT/MPS ]

  1. /*     
  2. SimpleInMovies
  3.  
  4. Sample programs demonstrating how to open and display
  5. QuickTime™ Movies.
  6.  
  7. SimpleInLOOP.c file contains the code for the routines 
  8. having to do with checking for the existance of the LOOP user data atom.
  9. This is the mechanism that can allow applications opening movies to set the
  10. loop state the movie was saved with.
  11. Applications that allow the user to change the state of a movie should also save
  12. the loop state if it changed since the movie was opened.
  13.  
  14. Guillermo A. Ortiz
  15. Macintosh Developer Technical Support
  16.  
  17. 10/08/92 -- New with code to check for loop atom in the user data and also to save the
  18. proper user data if the looping state changed.
  19.  
  20. */
  21.  
  22. #include <SimpleInMovie.h>
  23. short GetFileLoopState(DocRecHandle DocHandle);
  24. void SetLoopState(DocRecHandle wHndl);
  25. short GetCurrentLoopState(DocRecHandle wHndl);
  26. void UpdateLoopStateInfo(DocRecHandle wHndl);
  27. void FixWindowPosition(WindowPtr w,DocRecHandle wHndl);
  28. Boolean WPositionChanged(WindowPtr w,DocRecHandle DocHandle);
  29. void UpdateWindowPos(void);
  30.  
  31. short GetFileLoopState(DocRecHandle DocHandle)
  32. {
  33. UserData uData;
  34. short dataCount;
  35. Handle data;
  36. OSErr error;
  37.  
  38.     if ( !(data = NewHandle(4)) ) /* first try to make room for the result but if */
  39.       return (noLoop);           /* NewHandle fails return noLoop as the default */
  40.  
  41.     if ( uData = GetMovieUserData((*DocHandle)->wMovie) ) { /* get user data */
  42.       if ( dataCount = CountUserDataType(uData, 'LOOP')    ) {    /* if any count loop atoms */
  43.         error = GetUserData(uData, data, 'LOOP', 1); /* and get the first loop atom */
  44.  
  45.         if (*((short *)*data)) 
  46.           return (loopIsPalindrome);
  47.         else
  48.           return (loopNormal);
  49.       }
  50.     }
  51.     DisposeHandle(data);
  52.     
  53.     return noLoop; /* default */
  54. }
  55.  
  56.  
  57.  
  58. /* the movie came looping and here the correct state is set for it */
  59. void SetLoopState(DocRecHandle wHndl)
  60. {
  61.         switch ((*wHndl) -> loopState) {
  62.             case loopNormal:
  63.               MCDoAction((*wHndl)->wPlayer, mcActionSetLooping, (void *)loopNormal);
  64.               break;
  65.             case loopIsPalindrome: /* palindrome requires looping to be enabled. */
  66.               MCDoAction((*wHndl)->wPlayer, mcActionSetLooping, (void *)loopNormal);
  67.               MCDoAction((*wHndl)->wPlayer, mcActionSetLoopIsPalindrome, (void *)1);
  68.               break;
  69.         }
  70. }
  71.  
  72. short GetCurrentLoopState(DocRecHandle wHndl)
  73. {
  74. long mcInfo;
  75. short result = 0;
  76.  
  77.       if ( MCGetControllerInfo((*wHndl)->wPlayer, &mcInfo) )
  78.         DebugStr("\pCould not get controller info");
  79.         
  80.       if ( (mcInfo & mcInfoIsLooping) ) {
  81.         result++;
  82.         if ( (mcInfo & mcInfoIsInPalindrome) ) 
  83.           result++;
  84.       }
  85.       return result;
  86. }
  87.  
  88. void UpdateLoopStateInfo(DocRecHandle wHndl)
  89. {
  90. short loopState, dataCount;
  91. Handle loopy;
  92. UserData uData;
  93.  
  94.     loopState = GetCurrentLoopState(wHndl);
  95.     
  96.     if (loopState != (*wHndl)->loopState) { /* OK is different than the last time it was saved */
  97.       if (uData = GetMovieUserData( (*wHndl)->wMovie ) ) { /* let start by removing whatever */
  98.         dataCount = CountUserDataType(uData, 'LOOP');               /* is there.                         */
  99.         while (dataCount--)
  100.           RemoveUserData(uData, 'LOOP',1);
  101.       }
  102.       if (loopy = NewHandle(2) ) {                 /* get a handle */
  103.         if (loopState) {                        /* and add the atom if necessary */
  104.           switch (loopState) {
  105.             case loopNormal: 
  106.              *((short *) *loopy) = 0;
  107.              break;
  108.             case  loopIsPalindrome:
  109.               *((short *) *loopy) = 0x0100;
  110.               break;
  111.           }
  112.         AddUserData(uData, loopy, 'LOOP');
  113.         }
  114.       }
  115.     }
  116.     (*wHndl)->loopState = loopState;
  117.     DisposeHandle(loopy);
  118. }
  119.  
  120. /**********************************************************************************************//**********************************************************************************************/
  121. /**********************************************************************************************//**********************************************************************************************/
  122. /**********************************************************************************************//**********************************************************************************************/
  123. /* as a freebie we'll add here the code needed to get/set the WLOC user data atom.
  124.    This atom is used to keep the last position of the file so that it opens in the
  125.    same place.
  126. */
  127.  
  128. void FixWindowPosition(WindowPtr w,DocRecHandle DocHandle)
  129. {
  130. UserData uData;
  131. short dataCount;
  132. Point **data;
  133. OSErr error;
  134.  
  135.     if ( !(data = (Point **)NewHandle(4)) ) /* first try to make room for the result but if */
  136.       return;           /* NewHandle fails return  */
  137.  
  138.     if ( uData = GetMovieUserData((*DocHandle)->wMovie) ) { /* get user data */
  139.       if ( dataCount = CountUserDataType(uData, 'WLOC')    ) {    /* if any count loop atoms */
  140.         if ( !(error = GetUserData(uData, (Handle)data, 'WLOC', 1) )) /* and get the first loop atom */
  141.           MoveWindow(w, (*data)->h, (*data)->v, false);
  142.       }
  143.     }
  144.     DisposeHandle((Handle)data);
  145. }
  146.  
  147. Boolean WPositionChanged(WindowPtr w,DocRecHandle DocHandle)
  148. {
  149. UserData uData;
  150. short dataCount;
  151. Point **data;
  152. OSErr error;
  153. Boolean result = true;
  154.  
  155.     if ( !(data = (Point **)NewHandle(4)) ) /* first try to make room for the result but if */
  156.       return false;           /* NewHandle fails return who knows what the old position was */
  157.  
  158.     if ( uData = GetMovieUserData((*DocHandle)->wMovie) ) { /* get user data */
  159.       if ( dataCount = CountUserDataType(uData, 'WLOC')    ) {    /* if any count loop atoms */
  160.         if ( ! ( error = GetUserData(uData, (Handle)data, 'WLOC', 1) ) ) /* and get the first loop atom */
  161.           if( (w->portRect.left == (*data)->h) && (w->portRect.top ==(*data)->v) )
  162.             result = false;
  163.       }
  164.     }
  165.     DisposeHandle((Handle)data);
  166.     return result;
  167. }
  168.  
  169. void UpdateWindowPos(void)
  170. {
  171. short dataCount;
  172. Point **wCorner;
  173. UserData uData;
  174.  
  175. WindowPtr window;
  176. DocRecHandle wHndl;
  177. GrafPtr oldPort;
  178.  
  179.     GetPort(&oldPort);
  180.     
  181.     if (window = FrontWindow()) { /* don't bother if no movies to play */
  182.       SetPort(window);
  183.       wHndl = (DocRecHandle)GetWRefCon(window);
  184.       if (uData = GetMovieUserData( (*wHndl)->wMovie ) ) { /* let start by removing whatever */
  185.         dataCount = CountUserDataType(uData, 'WLOC');               /* is there.                         */
  186.         while (dataCount--)
  187.           RemoveUserData(uData, 'WLOC',1);
  188.       }
  189.       if (wCorner = (Point **)NewHandle(4) ) {                 /* get a handle */
  190.         (*wCorner)->h = window->portRect.left;
  191.         (*wCorner)->v = window->portRect.top;
  192.         LocalToGlobal((*wCorner));
  193.         AddUserData(uData, (Handle)wCorner, 'WLOC');
  194.         DisposeHandle((Handle)wCorner);
  195.       }
  196.     }
  197.     SetPort(oldPort);
  198. }
  199.  
  200.